import http from '@/utils/http'
import type { ApiResponse } from '@/types/api';
import type { Message } from '@/types/message';


// 预约请求参数接口
export interface Request {
    /**
     * 结束日期，不传默认为当天
     */
    endDate?: string;
    /**
     * 医生名称模糊查询
     */
    name?: string;
    /**
     * 页码
     */
    pageNum?: string;
    /**
     * 每页大小
     */
    pageSize?: string;
    /**
     * 开始日期
     */
    startDate?: string;
    /**
     * 预约状态查询(PENDING:待处理,ACCEPTED：就诊中, REJECTED:已拒绝,TIMEOUT:已超时,COMPLETED:已完成
     */
    status?: string;
    /**
     * 用户id
     */
    userId: string;
    [property: string]: any;
}

// 预约信息接口
export interface AppointmentVO {
    id: number;
    patientName: string;
    age: number;
    gender: string;
    avatar?: string;
    department: string;
    doctorName: string;
    appointmentTime: string;
    status: string;
    description?: string;
    isRead?: boolean;
    [property: string]: any;
}

// 分页响应接口
export interface PageResponse {
    records: AppointmentVO[];
    total: number;
    size: number;
    current: number;
    [property: string]: any;
}

// 预约消息响应接口
export interface AppointmentMessageResponse {
    /**
     * 消息列表
     */
    list: Message[];
    /**
     * 总数
     */
    total: number;
    /**
     * 未读消息数
     */
    unreadCount: number;
}

// 获取用户预约列表
export const getUserAppointments = (params: Request): Promise<ApiResponse<PageResponse>> => {
    return http({
        url: '/user/appointment/list',
        method: 'GET',
        params
    })
}

// 取消预约
export const cancelAppointment = (id: number): Promise<ApiResponse<any>> => {
    return http({
        url: `/user/appointment/cancel/${id}`,
        method: 'PUT'
    })
}

// 获取预约详情
export const getAppointmentDetail = (id: number): Promise<ApiResponse<AppointmentVO>> => {
    return http({
        url: `/user/appointment/detail/${id}`,
        method: 'GET'
    })
}

// 获取预约消息
export const getAppointmentMessages = (params?: {
    page?: number;
    pageSize?: number;
    status?: number;
}): Promise<ApiResponse<AppointmentMessageResponse>> => {
    return http({
        url: '/user/appointment/msg',
        method: 'GET',
        params
    })
}
